package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ScoreRulesV2Dao;
import cn.topevery.garden.entity.fetch.ScoreRulesV2Fetch;
import cn.topevery.garden.entity.po.ScoreRulesV2;
import cn.topevery.garden.entity.query.ScoreRulesV2Query;
import cn.topevery.garden.entity.vo.ScoreRulesV2VO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2022-01-07
 */
@Repository
public class ScoreRulesV2DaoImpl extends BaseDaoImpl<ScoreRulesV2> implements ScoreRulesV2Dao {
    @Override
    public <P extends DbCsp> List<ScoreRulesV2> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<ScoreRulesV2VO> listPage(ScoreRulesV2Query query) {
        String table = "t_score_rules_v2 tsrv";

        String columns = "tsrv.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tsrv.c_id desc");
        sqlQueryMate
                .where(true, "tsrv.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, ScoreRulesV2VO.class);
    }

    @Override
    public ScoreRulesV2 getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public DataPager<ScoreRulesV2> getList(ScoreRulesV2Fetch para) {
        String table = "t_score_rules_v2 tsrv";
        String columns = "tsrv.*";
        int pageIndex = para.getPageIndex() - 1;
        int pageSize = para.getPageSize();
        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tsrv.c_id desc");
        sqlQueryMate.where(true, "tsrv.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNoneBlank(para.getItem()), "c_item_id", ScriptConditionEnum.Eq, para.getItem())
                .where(true, "c_is_new", ScriptConditionEnum.Eq, 1)
                .where(true, "c_is_new", ScriptConditionEnum.Eq, null);
        return null;
    }

    @Override
    public DataPager<ScoreRulesV2> getHisList(ScoreRulesV2Fetch para) {
        int pageIndex = para.getPageIndex() - 1;
        int pageSize = para.getPageSize();
        SqlQueryMate sqlQueryMate = new SqlQueryMate("t_score_rules_v2").setColumns("*");
        sqlQueryMate.where(true, "c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(para.getEntityId()), "c_parent_clause_id", ScriptConditionEnum.Eq, para.getEntityId());
        return getDataPager(sqlQueryMate, pageSize, pageIndex, ScoreRulesV2.class);
    }
}
